#pragma once
#ifndef _BLOCK_H
#define _BLOCK_H

#include<memory>
#include<ctime>
#include<stdlib.h>
#include<vector>
#include<graphics.h>
#include "Teris.h"

namespace Game {
	class Block {
		friend void Teris::drawMemoryBlock(int x, int y, int blockColor, Teris::Token);
	public:
		using Map = std::vector<std::vector<int>>;
		Block();
		virtual ~Block();
		virtual void drop();
		virtual void reback();
		virtual void rotate(int offset);
		virtual void draw(const int leftMargin, const int topMargin);
		virtual void drawAdvanceBlock(const int leftMargin, const int topMargin);
		virtual void moveLeftRight(int offset);
		virtual bool isPositionCorrect(const Map& map);
		virtual void solidify(Map& map);
	private:
		int shift;
		int blockType;
		struct Position {
			int dx; // row
			int dy; // col
		};
		std::vector<Position> smallBlocks{ std::vector<Position>(4) };
		std::shared_ptr<IMAGE> img;
		static const std::vector<std::vector<int>> blockShape;
		static int smallBlockSize;
	protected:
		static std::vector<std::shared_ptr<IMAGE>> blockColor;
	};

}

#endif // !_BLOCK_H
